<?php include("includes/session.php"); ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Zeitgeist Resources - Find Resources</title>
<?php include('includes/categories.php');
if(isset($_GET['type']) || isset($_GET['category']) || isset($_GET['text']) || isset($_GET['country']))
{
	$search = "SELECT * FROM ".TBL_RESOURCES." WHERE ";
	$prev = false;
	if(isset($_GET['type']))
	{
		$search .= "type='".$_GET['type']."' ";
		$prev = true;
	}
	if(isset($_GET['category']))
	{
		if($prev)
			$search .= "AND ";
		$search .= "category='".$_GET['category']."' ";
		$prev = true;
	}
	if(isset($_GET['text']))
	{
		if($prev)
			$search .= "AND ";
		$search .= "(title LIKE '%".$_GET['text']."%' OR description LIKE '%".$_GET['text']."%') ";
		$prev = true;
	}
	if(isset($_GET['country']))
	{
		if($prev)
			$search .= "AND ";
		$search .= "countryCode='".$_GET['country']."' ";
		$prev = true;
	}
	$search .= "ORDER BY timestamp DESC";
	$res = $database->query($search);
	$num_res = mysql_num_rows($res);
	
	$start = 0;
	$maxResources = 30;
	if(isset($_GET['start']))
	{
		$start = $_GET['start'];
	}
}
else
{
	$res = $database->query("SELECT * FROM ".TBL_RESOURCES." ORDER BY timestamp DESC");
	$num_res = mysql_num_rows($res);
	
	$start = 0;
	$maxResources = 30;
	if(isset($_GET['start']))
	{
		$start = $_GET['start'];
	}
}
?>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=<?php echo GOOGLE_KEY; ?>" type="text/javascript">
</script>
<script type="text/javascript">
var map;
function initialize()
{
	if (GBrowserIsCompatible())
	{
		map = new GMap2(document.getElementById("map_canvas"));
		map.setCenter(new GLatLng(0, 0), 0);
		map.setUIToDefault();
		map.setMapType(G_SATELLITE_MAP);
		map.setZoom(1);
		
		<?php
		if($num_rows>0)
		{
			for($i=$start;$i<$num_res && $i<$start+$maxResources;$i++)
			{
				$name = mysql_result($res,$i,"title");
				$user = mysql_result($res,$i,"username");
				$latitude = mysql_result($res,$i,"latitude");
				$longitude = mysql_result($res,$i,"longitude");
				if($latitude)
					echo "addMarker($latitude, $longitude, '$name', '$user');";
			}
		}
		?>
	}
}
function addMarker(lat, long, name, user)
{
	if (GBrowserIsCompatible())
	{
		var marker = new GMarker(new GLatLng(lat, long));
		GEvent.addListener(marker,"mouseover",
			new Function("document.getElementById(\"map_name\").innerHTML = \""+name+"\";"));
		GEvent.addListener(marker,"click",
			new Function("window.location = \"profile.php?user="+user+"\";"));
		map.addOverlay(marker);
	}
}
</script>
<?php include("header.php"); ?>
	
			<br />
			<center>
			<table cellpadding="10" cellspacing="0" width="100%" class="border">
			<tr><td class="title" align="left">Location of Resources</td></tr>
			<tr>
				<td align="left">
					<!-- Google Map -->
					<center>
					<table cellpadding="3" cellspacing="0" width="230px">
					<tr>
						<td>
						<div id="map_canvas" style="width: 900px; height: 220px;"></div>
						</td>
					</tr>
					<tr>
						<td>
						<Center><b><div id="map_name"></div></b></Center>
						</td>
					</tr>
					</table>
					</center>
				</td>
			</tr>
			</table>